package com.zrf.base.knowledge.mulip;

/**
 * 子类1
 *
 * @author zhouruifeng
 *         create at 2017/3/19.
 */
public class Son1 {
    /**
     * count
     */
    private static int COUNT;
    /**
     * id
     */
    private static final int ID = COUNT++;
    /**
     * fath
     */
    private Father father;

    public Son1(Father father) {
        System.out.println("son");
        this.father = father;
        this.father.addReference();
    }

    protected void dispose() {
        System.out.println("dispose Rubbish" + ID);
        father.dispose();
    }

    public static void main(String[] args) {
        Father father = new Father();

        Son1 son1[] = {new Son1(father), new Son1(father), new Son1(father), new Son1(father)};

        for (Son1 r : son1) {
            r.dispose();
        }
    }
}
